package com.bjpowernode.servlet;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;

public class BServlet extends GenericServlet {
    @Override
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        //获取ServletContext对象
        ServletContext application = this.getServletContext();
        out.print("ServletContext对象是："+ application+"<br>");

        //取出来
        Object userObj = application.getAttribute("userObj");
        // 输出到浏览器
        out.print(userObj + "<br>");

        int age=17;
        if(age<18){
            application.log("对不起，你未成年，请绕行！", new RuntimeException("小屁孩，快走开，不适合你！"));
        }
    }
}
